﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;
using NetWork.Layer;
namespace UI
{
    public class UICopySweepEvent :MonoBehaviour
    {
        #region ui event
        public void OnSubmitClick()
        {
            GetComponent<UICopySweep>().Close();
        }

        public void OnMaskClick()
        {
            GetComponent<UICopySweep>().Close();
        }

        public void OnStopClick()
        {
            GetComponent<UICopySweep>().needStop=true;
        }
        #endregion

        #region network event
        public void OnSweepCopyClick(string chapterId, string levelId, int times)
        {
            var copySweep = new CSCopySweep();

            copySweep.chapterId = chapterId;
            copySweep.missionId = levelId;

            NetAPI.SendHttp(OpDefine.CSCopySweep, copySweep, (data, ok) =>
           {
               if (ok)
               {
                   SCCopySweep sweepObj = (SCCopySweep)data.kBody;

                   StaticData.playerData.AddResultObj(sweepObj.gain);


                   var level = UICopyData.GetUILevelData(GetComponent<UICopySweep>().levelId);
                   var powerCount = level.level_power_cost;

                   StaticData.playerData.Stamina -= powerCount;//

                    UICopyData.AddCurrentLevelChallengeCount(GetComponent<UICopySweep>().levelId, 1);


                   GetComponent<UICopySweep>().Refresh(sweepObj, times);
               }
           });
        }
        #endregion
    }
}